import { _decorator, Component, Label, Node } from 'cc';
import { LayerBase } from './LayerBase';
import { UILayerMgr } from './UILayerMgr';
import { UserInfo } from './UserInfo';
import { StartSceneGameMgr } from './StartSceneGameMgr';
import { gameMgr } from '../mainScene/gameMgr';
import { keepOneDecimalFullFomatFloat, randomNum } from '../utils/utils';
import { Adsdk } from '../Adsdk';
import { EnhanceEquipPanel } from './EnhanceEquipPanel';
import { EnhancePetPanel } from './EnhancePetPanel';
import { AudioMgr } from '../utils/AudioMgr';
const { ccclass, property } = _decorator;

@ccclass('GetCoinCrystalPanel')
export class GetCoinCrystalPanel extends LayerBase {
   
    @property(Label)
    useSeeAdvGetCrystalNumLabel:Label;
    @property(Label)
    useSeeAdvGetCoinNumLabel:Label;


    init(somedData?: any): void {
        this.useSeeAdvGetCrystalNumLabel.string =UserInfo.seeAdvGetCrystalUseNum+"/"+StartSceneGameMgr.ins.seeAdvGetCrystalTotalNum;
        this.useSeeAdvGetCoinNumLabel.string =UserInfo.seeAdvGetCoinUseNum+"/"+StartSceneGameMgr.ins.seeAdvGetCoinTotalNum;
     
    }

    onclickSeeAdvGetCrystalBtn(){
        AudioMgr.ins.playOneShot("audio/onclickAddCoinCrystal",0.8);

        if (UserInfo.seeAdvGetCrystalUseNum>=StartSceneGameMgr.ins.seeAdvGetCrystalTotalNum) {//使用完次数了
            StartSceneGameMgr.ins.createWidowTip("没有使用次数了每天再来吧");
        }
        else {
            Adsdk.instance.showVideo(() => {
                let rewardCrystalNum = 100;
                UserInfo.crystalMun += rewardCrystalNum;
                UserInfo.seeAdvGetCrystalUseNum += 1;
                StartSceneGameMgr.ins.saveGameDate();
                StartSceneGameMgr.ins.createWidowTip(`获得${rewardCrystalNum}个晶体`);
                UILayerMgr.getIns.resfreshUI(this.node.name);
                UILayerMgr.getIns.resfreshUI("equipPanel")
                UILayerMgr.getIns.resfreshUI("shopPanel")
                if (UILayerMgr.getIns.existLayerDic.containsKey("enhanceEquipPanel")) {
                    UILayerMgr.getIns.existLayerDic.get("enhanceEquipPanel").getComponent(EnhanceEquipPanel).renewCrystalLabel();
                }
                if (UILayerMgr.getIns.existLayerDic.containsKey("enhancePetPanel")) {
                    UILayerMgr.getIns.existLayerDic.get("enhancePetPanel").getComponent(EnhancePetPanel).renewCrystalLabel();
                }

            }, () => {

            })
        }
    }

    
    onclickSeeAdvGetCoinBtn(){
        AudioMgr.ins.playOneShot("audio/onclickAddCoinCrystal",0.8);

        if (UserInfo.seeAdvGetCoinUseNum>=StartSceneGameMgr.ins.seeAdvGetCoinTotalNum) {//使用完次数了
            StartSceneGameMgr.ins.createWidowTip("没有使用次数了每天再来吧");
        }
        else {
            Adsdk.instance.showVideo(() => {
                let rewardNum = 100;
                UserInfo.coinMun += rewardNum;
                UserInfo.seeAdvGetCoinUseNum += 1;
                StartSceneGameMgr.ins.saveGameDate();
                StartSceneGameMgr.ins.createWidowTip(`获得${rewardNum}个金币`);
                UILayerMgr.getIns.resfreshUI(this.node.name);
                UILayerMgr.getIns.resfreshUI("equipPanel")
                UILayerMgr.getIns.resfreshUI("shopPanel")
                if (UILayerMgr.getIns.existLayerDic.containsKey("enhanceEquipPanel")) {
                    UILayerMgr.getIns.existLayerDic.get("enhanceEquipPanel").getComponent(EnhanceEquipPanel).renewCoinLabel();
                }
                if (UILayerMgr.getIns.existLayerDic.containsKey("enhancePetPanel")) {
                    UILayerMgr.getIns.existLayerDic.get("enhancePetPanel").getComponent(EnhancePetPanel).renewCoinLabel();
                }
            }, () => {

            })
        }
    }
}


